//
//  UIView+Theme.m
//  夜间模式
//
//  Created by Burn on 2018/10/19.
//  Copyright © 2018年 buren. All rights reserved.
//

#import "UIView+Theme.h"
#import "ThemeManager.h"
#import <objc/runtime.h>



@implementation UIView (Theme)

- (void)setType:(id)type{
    objc_setAssociatedObject(self, @selector(type), type, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (id)type{
    return objc_getAssociatedObject(self, @selector(type));
}

/**开始监听*/
- (void)startMonitor{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeColor) name:@"CHANGECOLOR" object:nil];
    
}

//*修改颜色/
- (void)changeColor{
    switch ([self.type integerValue]) {
        case ThemeTypeNormal:
            self.backgroundColor = [ThemeManager shareInstance].themeNormalColor;
            break;
        case ThemeTypeBlack:
            self.backgroundColor = [ThemeManager shareInstance].themeBlackColor;
            break;
        case ThemeTypeRed:
            self.backgroundColor = [ThemeManager shareInstance].themeRedColor;
            break;
        case ThemeTypeClear:
            self.backgroundColor = [ThemeManager shareInstance].themeClearColor;
            break;

        default:
            break;
    }
}

/*设置颜色类型和对应颜色*/
- (void)nightWithType:(ThemeType)type{
    self.type = [NSNumber numberWithInteger:type];
    [self changeColor];
    [self startMonitor];
    
    // 调用设置字体颜色的方法
    [self initTextColor];
}

/*设置字体颜色的方法*/
- (void)initTextColor{
    NSLog(@"UIView + Theme");
}

@end
